
package com.nvshen.zhangmeiying.utils;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author wxc
 */
public abstract class BaseArrayListAdapter<T> extends BaseAdapter
{

    protected List<T> mList;
    protected Context mContext;
    protected AbsListView mAbsListView;

    public BaseArrayListAdapter(Context context){
        this.mContext = context;
    }

    public int getCount() {
        if(mList != null)
            return mList.size();
        else
            return 0;
    }

    public Object getItem(int position) {
        return mList == null ? null : mList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    abstract public View getView(int position, View convertView, ViewGroup parent);

    public void setList(List<T> list){
        this.mList = list;
        notifyDataSetChanged();
    }

    public List<T> getList(){
        return mList;
    }

    public void setList(T[] list){
        ArrayList<T> arrayList = new ArrayList<T>(list.length);
        for (T t : list) {
            arrayList.add(t);
        }
        setList(arrayList);
    }

    public AbsListView getAbsListView() {
        return mAbsListView;
    }

    public void setAbsListView(AbsListView mAbsListView) {
        this.mAbsListView = mAbsListView;
    }
}
